import { Channel, Token } from '@/types/data'
const TOKEN_KEY = 'geek-h5-token'
const CHANNEL_KEY = 'geek-h5-channels'
const HISTORIES_KEY = 'geek-h5-histories'
export function setToken(token: Token) {
  localStorage.setItem(TOKEN_KEY, JSON.stringify(token))
}

export function getToken(): Token {
  return JSON.parse(localStorage.getItem(TOKEN_KEY) || '{}')
}

export function removeToken() {
  localStorage.removeItem(TOKEN_KEY)
}

export function hasToken(): boolean {
  return !!getToken().token
}

/* channels本地存储 */
export function setChannels(channels: Channel[]) {
  localStorage.setItem(CHANNEL_KEY, JSON.stringify(channels))
}

export function getChannels(): Channel[] {
  return JSON.parse(localStorage.getItem(CHANNEL_KEY) || '[]')
}

export function setLocalHistories(histories: string[]) {
  localStorage.setItem(HISTORIES_KEY, JSON.stringify(histories))
}

export function getLocalHistories(): string[] {
  return JSON.parse(localStorage.getItem(HISTORIES_KEY) || '[]')
}
